//
//  ShareSetting.m
//  Finder
//
//  Created by cdm on 11-3-27.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "ShareSetting.h"

@implementation Tweet

@synthesize name;
@synthesize url;

- (void)dealloc
{
    [self.name release];
    [self.url release];
    [super dealloc];
}

@end

@implementation ShareSetting

@synthesize content;
@synthesize tweets;

- (id)init
{
    self = [super init];
    if (self) {
        self.tweets = [[NSMutableArray alloc] init];
    }
    
    return self;
}

- (void)dealloc
{
    [self.content release];
    [self.tweets release];
    [super dealloc];
}

+ (ShareSetting *)settingFromPlist:(NSString *)name
{
    ShareSetting *shareSetting = [[[ShareSetting alloc] init] autorelease];
    
    //NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:nil];
    NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:nil inDirectory:nil forLocalization:[AppLanguage getLanguageAsString]];
    NSDictionary *shareSettingDict = [NSDictionary dictionaryWithContentsOfFile:path];
    
    shareSetting.content = [shareSettingDict objectForKey:@"Content"];
    
    NSArray *tweetsArray = [shareSettingDict objectForKey:@"Tweets"];
    for (NSDictionary *tweetDict in tweetsArray) {
        Tweet *tweet = [[Tweet alloc] init];
        tweet.name = [tweetDict objectForKey:@"Name"];
        tweet.url = [tweetDict objectForKey:@"URL"];
        [shareSetting.tweets addObject:tweet];
        [tweet release];
    }
    
    return shareSetting;
}

@end
